package top.malaoshi.service;

import org.springframework.stereotype.Service;
import top.malaoshi.entity.UserModel;
import top.malaoshi.mapper.IUserMapper;
import top.malaoshi.model.Result;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LoginSrvImpl {
    @Resource
    private IUserMapper dao;

    public Result login(String phone, String password){
        System.out.println("LoginSrvImpl:"+phone+"---"+password);
        List<UserModel> list=dao.queryByPhone(phone);
        Result res=new Result();
        if(list.size()==1){
            UserModel um=list.get(0);
            String passwordDb=um.getPassword();
            if (password.equals(passwordDb)){
                res.setCode(0);
                res.setMsg("登录成功！");
            }else{
//                res.setCode(100);
//                res.setMsg("密码错误！");
                //用户名或密码错误
                res.setCode(101);
                res.setMsg("用户名或密码错误");
            }
        }else{
//            res.setCode(100);
//            res.setMsg("用户名不存在！");
            res.setCode(102);
            res.setMsg("用户名或密码错误");
        }
        return res;
    }
}
